//	Company:	HTHK
//	NAME:	    ProjectServlet.java
//	TITLE:	    The maintence of Project in Time Sheet System
//	FUNCTION:	The flow control interface of class Project associate with the table
//	BY:	        Kodak Xu
//	DATE:	    09/12/2003
//	Update_by	Poly Li
//	Update_date	16-01-2004
//	Update_by	Beyes Xia
//	Update_date	2004-2-13 17:42
// --------------------------------------------------------------
// MODIFICATION HISTORY
// --------------------------------------------------------------
//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// --------------------------------------------------------------
package tss.project;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.sql.*;

import com.ffpc.sql.*;
import com.ffpc.struts.StrutsMessage;
import com.ffpc.util.DateFormatter;

import tss.common.DBServlet2;

public class ProjectServlet extends DBServlet2 
{
	@Override
	protected String perform(HttpServletRequest request,
                             HttpServletResponse response,
                             StrutsMessage message)
    throws  ServletException,
            IOException,
            SQLException,
            DataException,
            Exception
   {
      String action = new String(request.getParameter("formAction"));

      ProjectBean project = ProjectProcess.createBean();
      
	  project.setProject_name(request.getParameter("project_name"));
      project.setProject_category_name(request.getParameter("project_category_name"));
      project.setComments(request.getParameter("comments"));
      //Add by Poly Li
      String fromStr = "";
	  String toStr = "";
	  if ((request.getParameter("year_from")!=null && request.getParameter("year_from").length()!=0) && (request.getParameter("month_from")!=null && request.getParameter("month_from").length()!=0)) 
		  fromStr = request.getParameter("year_from")+"/"+request.getParameter("month_from");

	  if ((request.getParameter("year_to")!=null && request.getParameter("year_to").length()!=0) && (request.getParameter("month_to")!=null && request.getParameter("month_to").length()!=0)) 
		  toStr = request.getParameter("year_to")+"/"+request.getParameter("month_to");

      project.setUpd_date(DateFormatter.format(this.getDate()));
      project.setUpd_by(getUser().getUser_id());
	//Add by Poly Li
	project.setChargeable_ind(request.getParameter("chargeable_ind"));
	  project.setEffective_range_from(fromStr);
	  project.setEffective_range_to(toStr);
	  
	project.setProject_group_name(request.getParameter("project_group_name"));

      if (action.trim().equalsIgnoreCase("Create"))
      {
         project.setCreate_date(DateFormatter.format(this.getDate()));
         project.setCreate_by(getUser().getUser_id());
        if (ProjectProcess.insert(this.getConnection(),project)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure");
      }
      else if (action.trim().equalsIgnoreCase("Update"))
        if (ProjectProcess.update(this.getConnection(),project)>0)
            message.setMessage("Save successfully.");
        else
            message.setMessage("Save failure.");
      else if (action.trim().equalsIgnoreCase("Delete"))
        if (ProjectProcess.delete(this.getConnection(),project)>0)
            message.setMessage("Delete successfully.");
        else
            message.setMessage("Delete failure.");
      else
            message.setMessage("No action mapped!");


      return "tss/project/ProjectSearch.jsp";
   }
}